package com.hfkh.keyun.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkh.keyun.entity.Unit;
import com.hfkh.keyun.mapper.UnitMapper;
import com.hfkh.keyun.service.UnitService;
import com.hfkh.keyun.util.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class UnitServiceImpl extends ServiceImpl<UnitMapper, Unit>implements UnitService {

    @Resource
    private UnitMapper unitMapper;

    @Override
    public PageResult<List<Unit>> UnitList(Integer majorId, Integer page, Integer size) {
        PageResult<List<Unit>> pageResult = new PageResult<>();
        // 启动分页
        PageHelper.startPage(page, size, true);
        // 获取电子文档列表
        List<Unit> docList = unitMapper.UnitList(majorId);
        // PageInfo分页对象
        PageInfo<Unit> pageInfo = new PageInfo<>(docList);
        pageResult.setPages(pageInfo.getPages());
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setPageNum(pageInfo.getPageNum());
        pageResult.setPageSize(pageInfo.getPageSize());
        pageResult.setList(pageInfo.getList());

        return pageResult;
    }

    @Override
    public List<Unit> selUnitList(Integer majorId) {
        return unitMapper.UnitList(majorId);
    }
}
